package com.ys.erp.common.util;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

/**
 * @author lwj
 * @date 2025/9/12
 */
public class YsFileUtil {

    public static ByteArrayOutputStream downloadFile(String urlString) throws IOException {
        URL url = new URL(urlString);
        InputStream inputStream = url.openStream();

        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        byte[] dataBuffer = new byte[1024];
        int bytesRead;
        while ((bytesRead = inputStream.read(dataBuffer, 0, 1024)) != -1) {
            byteArrayOutputStream.write(dataBuffer, 0, bytesRead);
        }

        inputStream.close();
        return byteArrayOutputStream;
    }

}
